<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.wxtf.platform.plugins.user.*"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	UserBean user = (UserBean)request.getSession().getAttribute("userBean");
	String _db = user.getDbType();
	String org = user.getCurOrgName();
	String orgId = user.getCurOrgId();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>"/>
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta http-equiv="pragma" content="no-cache"/>
		<meta http-equiv="cache-control" content="no-cache"/>
		<meta http-equiv="expires" content="0"/>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>查看下级库存</title>
		
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/Aqua/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/<%=user.getUserCss()%>/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/ligerui-icons.css" />
		<link type="text/css" rel="stylesheet" href="resource/css/style.css" />

		<script type="text/javascript" src="js/jquery/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="ligerUI/js/core/base.js"></script>
		<script type="text/javascript" src="ligerUI/js/ligerui.min.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="js/validata.js"></script>

		<script type="text/javascript" src="ligerUI/js/plugins/ligerGrid.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerForm.js"></script>
	    <script src="ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
	    <script src="ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script>		
<script type="text/javascript">
var _db = '<%=_db%>';

_jsonObj.classname = "com.wxtf.platform.main.contraceptives.LowerLevelAction";
_jsonObj.methodname = "queryPage";

var manager;
var tmadName;
$(function(){
	manager = $("#grid").ligerGrid({
		url: _url, width: '100%', height: '100%',enabledSort:false,delayLoad:true,
		usePager: false, rownumbers: true, alternatingRow: true,async:false,
		columns: [
			{ display: '药具种类', name: 'tmgd_name', width:100, align: 'left' },
			{ display: '药品名称', name: 'tmad_name', width:100, align: 'left' ,render: function(record, index, value, oth){
					return "<a href='javascript:yaopinming("+ JSON.stringify(record) + ")'>"+record.tmad_name+"</a>";
				}
			},
			{ display: '生产厂家', name: 'tmad_company_name', width: 100, align: 'left' },
			{ display: '规格', name: 'tmad_spec', width:  100, align: 'left' },
			{ display: '价格', name: 'tmad_price', width:  100, align: 'left' },
			{ display: '批号', name: 'tmad_batch_code', width:100, align: 'left' },			
			{ display: '上期库存', name: 'back_tmascd_num', width:100, align: 'left' },
			{ display: '入库数量', name: 'tmaid_num', width: 100, align: 'left' },
			{ display: '出库数量', name: 'tmaod_num', width:  100, align: 'left' },
			{ display: '结余', name: 'tmascd_num', width:  100, align: 'left', type:'int',render: function(record, index, value, oth){
					return value*100/100;
				}
			},			
			{ display: '宣传', name: 'tmascd_num_c', width:100, align: 'left' },
			{ display: '盘盈亏', name: 'tmascd_num_y', width: 100, align: 'left' },
			{ display: '报废', name: 'tmascd_num_s', width:  100, align: 'left' },			
			{ display: '库存数量', name: 'num', width:  100, align: 'left' },			
			{ display: '金额', name: 'money', width:  100, align: 'left', type:'float',render: function(record, index, value, oth){
					return value*100/100;
				}
			}
		]
	});
	//药品出库入库
	tmadName = $("#tmadname").ligerGrid({
		url: _url, width: '540', height:'325',enabledSort:false,async:false,delayLoad:true,pageSize:100,
		usePager: true, rownumbers: true, alternatingRow: true, enabledEdit: true, groupColumnName:'t_type',
		columns: [
			{ display: 't_type', name: 't_type', hide: true, width: 1 },
			{ display: '药品名称', name: 'tmad_name', width: 100, align: 'left' },			
			{ display: '生产厂家', name: 'tmad_company_name', width: 100, align: 'left' },
			{ display: '数量', name: 'num', width: 70, align: 'left'},
			{ display: '办理人', name: 'create_by', width: 70, align: 'left' },
			{ display: '办理时间', name: 'create_time', width: 90, align: 'left' },
			{ display: '类型', name: 'leixing', width: 50, align: 'left'}
		]	
	});
	$("#org_id").find("option").remove();
	var param = {
		"classname": "com.wxtf.platform.main.contraceptives.LowerLevelAction",
		"methodname": "selectSubOrgId",
		"logicdata": [],
		"extenddata": []
	};
	callserver(param, function(data, satus){
		$("#org_id").append('<option value="">--请选择--</option>');
		$.each(data, function (i, item) {
        	 $("#org_id").append('<option value="'+item.department_id+'">'+item.caption+'</option>');
        });
	},function(data, satus){
		warningTip(data.resultrecord);
	});
});
/*
*根据机构id查询盘点名称
*/
function orgIdChange(v){
	var param = {
		"classname": "com.wxtf.platform.main.contraceptives.LowerLevelAction",
		"methodname": "selectTmaStoreCheckByTmascmName",
		"logicdata": [],
		"extenddata": []
	};
	param.logicdata = "[{\"org_id\":\""+v+"\"}]";
	$("#tmascm_id").find("option").remove();
	callserver(param, function(data, textStatus){
		$("#tmascm_id").append('<option value="">--请选择--</option>');
		$.each(data, function (i, item) {
        	 $("#tmascm_id").append('<option value="'+item.tmascm_id+'">'+item.tmascm_name+'</option>');
        });
	}, function(data, textStatus){
		warningTip(data.resultrecord);
	});
}
/*
*根据盘点名称查询
*/
function tmascmIdChange(v){
	_jsonObj.logicdata = "[{\"tmascm_id\":\""+v+"\",\"org_id\":\""+$("#org_id").val()+"\"}]";
	manager.setOptions({url:_url,parms: _jsonObj});
}
/*
*药品名称
*/
function yaopinming(record){	
	initWindowByDiv2('tmadname', '药品查看', 565, 395, closeWin);
	var param = {
		"classname": "com.wxtf.platform.main.contraceptives.TmaStoreCheckDetailAction",
		"methodname": "selectTmaDictionaryByTmadName",
		"logicdata": [],
		"extenddata": []
	};
	param.logicdata = '[{"tmad_name":"'+record.tmad_name+'","org_id":"'+$("#org_id").val()+'"}]';
	tmadName.setOptions({url:_url,parms: param});
}
/*
 * 表格刷新
 */
function reload(){
	_jsonObj.methodname = "queryPage";
	_jsonObj.logicdata = "[]";
	manager.loadData();
}
/*
 * 导出
 */
function expData(){
	var org_id = $("#org_id").val();
	var tmascm_id = $("#tmascm_id").val();
	if(org_id==""){
		warningTip("请选择要导出的机构");
		return;
	}
	if(tmascm_id==""){
		warningTip("请选择要导出的盘点名称");
		return;
	}
	var param = {
		"classname": "com.wxtf.platform.main.contraceptives.LowerLevelAction",
		"methodname": "expData",
		"logicdata": [],
		"extenddata": []
	};	
	param.logicdata = "[{\"tmascm_id\":\""+tmascm_id+"\",\"org_id\":\""+org_id+"\"}]";	
	callserver(param, function(data, textStatus){
		if(data.result){
			downloadFile(data.resultrecord);
		} else {
			warningTip(data.resultrecord);
		}
	}, function(data, textStatus){
	});
}
</script>
</head>
	<body>
		<div>		
		组织机构：
		<select id="org_id" name="org_id" onchange="orgIdChange(this.value);" style=" width: 182px;">
		</select>
		盘点名称：
		<select id="tmascm_id" name="tmascm_id" onchange="tmascmIdChange(this.value);" style=" width: 182px;">
		</select>
		<input class="btn2" value="导出" type="button" onclick="expData();" />
		</div>
		<div id="grid"></div>
		<!-- 药品名称 -->
		<div id="tmadname"></div>
	</body>
</html>